
#include "framework.h"
#include <sys/time.h>
#include <time.h>

int SFW_LogOutput::m_outputfd;

void SFW_LogOutput::LogOutput(int type, string msg)
{
	m_outputfd = 0;

	/* date time format. */
	struct timeval tv;
	struct tm* ptm;
	char now[256];

	memset(now, 0x00, sizeof(now));
	gettimeofday(&tv, NULL);
	ptm = localtime(&tv.tv_sec);
	
	strftime(now, 256, "%Y/%m/%d %H:%M:%S", ptm);
	sprintf(now, "%s.%d", now, tv.tv_usec);
	string buffer = now;

	switch(type)
	{
	case 1:
		/* Trace */
		buffer.append(" [TRACE]");
		break;

	case 2:
		/* Debug */
		buffer.append(" [DEBUG]");
		break;

	case 3:
		/* FATAL */
		buffer.append(" [FATAL]");
		break;
		
	case 4:
		/* INFO */
		buffer.append(" [INFO]");
	}

	buffer.append(" ").append(msg).append("\n");

	/* write */
	write(m_outputfd, buffer.c_str(), buffer.length());
}

